<?php

namespace apiend\modules\setting\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\setting\models\VoltageSearch;
use yii\helpers\ArrayHelper;
use common\models\work\Voltage;

/**
 * 电压等级管理
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class VoltageController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return ArrayHelper::merge(parent::verbs(), [
            '*' => ['GET'],
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public $modelClass = VoltageSearch::class;

    /**
     * 电压等级管理
     * @return mixed
     */
    public function actionIndex() {
        /* @var $model VoltageSearch */
        $model = new $this->modelClass;
        return $model->configs();
    }

    /**
     * 电压等级管理
     * @return mixed
     */
    public function actionList() {
        /* @var $model VoltageSearch */
        $model = new $this->modelClass;
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    /**
     * 电压等级显示
     * @return mixed
     */
    public function actionView($id) {
        return $this->findModel($id);
    }

    /**
     * 电压等级信息更新
     * @param null|integer $id 电压等级主键
     * @return mixed
     */
    public function actionUpdate($id = null) {
        $model = Voltage::findOrNew($id);
        if (Yii::$app->request->isPost) {
            $params = Yii::$app->request->post();
            if (!$model->load($params, '')) {
                parent::error('数据提交失败');
            }
            return $model->save();
        }
        return $model;
    }

    /**
     * 删除电压等级记录
     * @param integer $id 电压等级主键
     * @return mixed
     */
    public function actionDelete($id) {
        $model = $this->findModel($id);
        if (!$model->delete()) {
            parent::error('电压等级删除失败');
        }
        return true;
    }

}
